package org.jsola.hr.helper;

import org.jsola.hr.dto.FacilitatorAddDTO;
import org.jsola.hr.dto.FacilitatorUpdateDTO;
import org.jsola.hr.entity.FacilitatorDO;
import org.jsola.hr.query.FacilitatorQuery;
import org.jsola.hr.service.IFacilitatorService;
import org.jsola.hr.vo.FacilitatorVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 卫人云-服务商
 *
 * @author zhr
 */
@Component
public class FacilitatorTestHelper extends BaseTestHelper {
    
    @Autowired
    private IFacilitatorService facilitatorService;

    /**
     * 生成add测试数据
     * @return FacilitatorAddDTO
     */
    public FacilitatorAddDTO getFacilitatorAddDTO(){
        FacilitatorAddDTO facilitatorAddDTO = new FacilitatorAddDTO();
        facilitatorAddDTO.setName(getRandomValue("varchar",50));
        facilitatorAddDTO.setAdminName(getRandomValue("varchar",50));
        facilitatorAddDTO.setAdminUserId(getRandomValue("varchar",32));
        facilitatorAddDTO.setCity(getRandomValue("varchar",50));
        facilitatorAddDTO.setContactNumber(getRandomValue("varchar",11));
        return facilitatorAddDTO;
    }


    /**
     * 生成update测试数据
     * @return FacilitatorUpdateDTO
     */
    public FacilitatorUpdateDTO getFacilitatorUpdateDTO(FacilitatorVO facilitatorVO){
        return facilitatorService.selectDOById(facilitatorVO.getId(), SITE_ID).to(FacilitatorUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return FacilitatorQuery
     */
    public FacilitatorQuery getFacilitatorQuery() {
        FacilitatorQuery facilitatorQuery = new FacilitatorQuery();
        List<FacilitatorDO> facilitatorDOList = facilitatorService.list(new FacilitatorDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(facilitatorDOList)) {
            FacilitatorDO facilitatorDO = facilitatorDOList.get(0);
            facilitatorQuery = facilitatorDO.to(FacilitatorQuery.class);
        }
        return facilitatorQuery;
    }

    /**
     * 保存示例
     * @return FacilitatorVO
     */
    public FacilitatorVO saveFacilitatorExample(){
        FacilitatorAddDTO addDTO = this.getFacilitatorAddDTO();
        FacilitatorVO facilitatorVO = facilitatorService.save(addDTO,buildTokenUser());
        return facilitatorVO;
    }


}

